<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //随机取整
        function rangeRandom(a,b) {
            var max = a > b ? a : b
            var min = a > b ? b : a
            var res = parseInt(Math.random() * (max - min + 1)) + min
            return res 
        }


        console.log(rangeRandom(99,101));
        //随机取整去0
        function rangeRandomNo0(a,b) {
            var max = a > b ? a : b 
            var min = a > b ? b : a
            var res = parseInt(Math.random() * (max - min + 1)) + min
            if (res === 0) {
                res = rangeRandomNo0(max,min)
            } 
            return res
        }
        var obj = {}
        for (var  i = 0; i < 9999; i++) {
            var res = rangeRandomNo0(-2,1)
            if (obj[res] === undefined) {
                obj[res] = 1
            }else{
                obj[res] ++
            }
        }
        console.log(obj);
    </script>
</body>
</html>